﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using WmsApp.WmsService;

namespace WmsApp.UI
{
    public partial class LookupEditCompose : DevExpress.XtraEditors.XtraUserControl
    {
        public LookupEditCompose()
        {
            InitializeComponent();
        }

   
        public string BindCode { get; set; }
        public string BindName { get; set; }
        public object EntityObject { get; set; }

        public void DataBinding()
        {

        }

        private void BindingLookUpEditProvider(LookUpEdit lookUpEdit, TextEdit valueTextEdit)
        {
            var itemLookUpEdit = lookUpEdit;
            itemLookUpEdit.Properties.Columns.AddRange(new DevExpress.XtraEditors.Controls.LookUpColumnInfo[] {
            new DevExpress.XtraEditors.Controls.LookUpColumnInfo("OWNERNO", "代码"),
            new DevExpress.XtraEditors.Controls.LookUpColumnInfo("OWNERNAME", "名称")});
            itemLookUpEdit.Properties.DisplayMember = "OWNERNO";
            itemLookUpEdit.Name = "LookUpEditCustomer";
            itemLookUpEdit.Properties.ValueMember = "OWNERNO";
            itemLookUpEdit.Properties.NullText = "";
            itemLookUpEdit.Properties.DataSource = Factory.WmsServiceFactory.GetServiceClient().GetCustomers();

            itemLookUpEdit.EditValueChanging += (sender, e) =>
            {

                var customer = (Customer)itemLookUpEdit.Properties.GetDataSourceRowByKeyValue(e.NewValue);
                if (customer != null)
                {
                    valueTextEdit.EditValue = customer.OWNERNAME;
                }
            };
        }
    }
}
